<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="classes/conndb.jsp"%>
<%@ include file="classes/GUID.class.jsp"%>

<%
	PreparedStatement ps = null;
	Connection con = null;
	ResultSet rs =null;
	
	String message_id = request.getParameter("message_id").equals("") ? "" : request.getParameter("message_id");
	String userid = request.getParameter("userid").equals("") ? "" : request.getParameter("userid");
	String is_public = request.getParameter("is_public").equals("") ? "" : request.getParameter("is_public");
	String answer_time = request.getParameter("answer_time").equals("") ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()) : request.getParameter("answer_time");
	String content = request.getParameter("content").equals("") ? "" : request.getParameter("content");
	String reply_id = getGUID();
	
	int incount = 0;
	int upcount = 0;
	String insql = "insert into cms_reply_comment (reply_id,message_id,content,operate_time,is_public,operator) values (?,?,?,to_date(?, 'yyyy-mm-dd hh24:mi:ss'),?,?)";
	String upsql = "update cms_public_comment set status='2',is_public =? where message_id =?";
		try {
			con = getConnection();
			ps = con.prepareStatement(insql);
			ps.setObject(1, reply_id);
			ps.setObject(2, message_id);
			ps.setObject(3, content);
			ps.setObject(4, answer_time);
			ps.setObject(5, is_public);
			ps.setObject(6, userid);
			incount = ps.executeUpdate();
			
			ps = con.prepareStatement(upsql);
			ps.setObject(1, is_public);
			ps.setObject(2, message_id);
			upcount = ps.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			closeConn(con, ps, rs);
		}

	if (incount >0 && upcount >0) {
		out.print("{\"operate_status\":\"1\"}");
	} else {
		out.print("{\"operate_status\":\"0\"}");
	}
%>